/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import 'package:flutter/material.dart';
import 'package:platform_component_demo/view/custom_web_view.dart';
import './utile/const_string.dart';
import './page/view_page.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'PlatformView Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
      routes: <String , WidgetBuilder>{
        Routers.web:(BuildContext context) => 
            const CustomWebView(),
        Routers.text:(BuildContext context) => 
            const ViewPage(viewName: Strings.text),
        Routers.textInput:(BuildContext context) => 
            const ViewPage(viewName: Strings.textInput),
        Routers.textArea:(BuildContext context) => 
            const ViewPage(viewName: Strings.textArea),
        Routers.span:(BuildContext context) => 
            const ViewPage(viewName: Strings.span),
        Routers.search:(BuildContext context) => 
            const ViewPage(viewName: Strings.search),
        Routers.richText:(BuildContext context) => 
            const ViewPage(viewName: Strings.richText),
      },
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.web);
              }, 
              child: const Text(Strings.web)
            ),
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.text);
              }, 
              child: const Text(Strings.text)
            ),
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.textInput);
              }, 
              child: const Text(Strings.textInput)
            ),
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.textArea);
              }, 
              child: const Text(Strings.textArea)
            ),
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.span);
              }, 
              child: const Text(Strings.span)
            ),
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.search);
              }, 
              child: const Text(Strings.search)
            ),
            ElevatedButton(
              onPressed: (){
                Navigator.pushNamed(context, Routers.richText);
              }, 
              child: const Text(Strings.richText)
            ),
          ],
        ),
      ),
    );
  }
}
